﻿using GetWebsite.GUI.Base;

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace GetWebsite.GUI.ViewModels
{
    public class VMMain : ViewModelBase
    {

        public VMMain()
        {
            DownloadBlogCommand = new CommandBase();
            DownloadBlogCommand.ExecuteAction = new Action<object>(DownloadBlog);
            DownloadBlogCommand.CanExecuteAction = new Func<object, bool>(CanDownloadBlog);
        }

        private bool CanDownloadBlog(object arg)
        {
            return true;
        }

        private void DownloadBlog(object obj)
        {
            var  isFinish =  cnBlog.GetSingleContent(Url, "");
            if (isFinish.isTrue)
            {
                MessageBox.Show(isFinish.msg);
                Url = "";
            }
            else
            {
                MessageBox.Show(isFinish.msg);
            }
        }

        private string _url = "";
        private string _title = "";
        private string _author = "";
        private string _publishtime = "";

        public string Url
        {
            get { return _url; }
            set { _url = value; OnPropertyChanged(); }
        }

        public string Title
        {
            get { return _title; }
            set { _title = value; OnPropertyChanged(); }
        }

        public string Author
        {
            get { return _author; }
            set { _author = value; OnPropertyChanged(); }
        }

        public string Publishtime
        {
            get { return _publishtime; }
            set { _publishtime = value; OnPropertyChanged(); }
        }

        public CommandBase? DownloadBlogCommand { get; set; } = null;
        private CnBlog cnBlog  = new CnBlog();
    }
}
